pepperstad.Person = function(opts) {

    this.id = pepperstad.Person.prototype.personId++;
    this.name = opts.name || "Unnamed";
    this.age = opts.age || 30;
    this.strength = opts.strength || 5;
    this.job = null;
    this.skills = opts.skills || [];
    /**
     * Happiness ranges from 1 (unhappy) to 10 (very happy). Defaults to 5 (content).
     */
    this.happiness = 5;

    this.listSkills = function() {
        var skill, i, str = "";
        for (i = 0; i < this.skills.length; i++) {
            skill = this.skills[i];
            str += skill.name + "(" + highlight(skill.level) + ") ";
        }
        return str;

        function highlight(skillLevel) {
            return skillLevel > 5 ? "<em>" + skillLevel + "</em>" : skillLevel;
        }
    };

    this.getJobName = function () {
        return this.job ? this.job.type : "Unemployed";
    };

};
// Static field
pepperstad.Person.prototype.personId = 0;

pepperstad.Unit = function(opts) {

    this.person = opts.person;
    this.hitpoints = 25;
    this.armor = [
        { name : "clothes", defenseValue : 1}
    ];
    this.weapons = [
        { name : "barehands", attackValue : 1}
    ];
    this.equipment = [];
    /**
     * Current unit location
     * @type pepperstad.Coord
     */
    this.location = null;
    /**
     * @type pepperstad.Coord
     */
    this.destination = null;

    /**
     * @param dmg number of hitpoints damage received
     * @return boolean if unit died
     */
    this.damage = function (dmg) {
        if (dmg > this.calculateDefense()) {
            this.hitpoints = this.hitpoints - dmg;
        }
        return this.hitpoints < 1;
    };

    /** updates the position of the unit */
    this.update = function() {
        // todo impl: <travel towards destination coordinate by calculating speedX and speedY each update>
//        this.updateX();
//        this.updateY();
//        var newposX = parseInt(this.getNode().css("left")) + this.getSpeedX();
//        this.getNode().css("left", newposX + "px");
//        var newposY = parseInt(this.getNode().css("top")) + this.getSpeedY();
//        this.getNode().css("top", newposY + "px");
    };
    this.calculateDefense = function() {
        var sum = 0;
        $.each(this.armor, function(index, armorItem) {
            sum += armorItem.defenseValue;
        });
        return sum;
    };
};

pepperstad.Skill = function() {
    this.name = null;
    /**
     * How skilled a person is from 0 - 9
     */
    this.level = 0;
    /**
     * Percent to level up in this skill
     */
    this.progressToNextLevel = 0;
};

pepperstad.Raider = function() {
    this.prototype = new pepperstad.Unit();

    this.update = function () {
        // <travel towards nearest building>
    }
};

pepperstad.Leader = function() {
    this.prototype = new pepperstad.Raider();

    /**
     * Range from 1-5 where 1 is stupid and 5 is genius.
     * Determines what kind of attack will be used,
     * and how long the leader will wait for group to grow before charging
     */
    this.intelligence = 1;
};

pepperstad.Guard = function() {
    this.prototype = new pepperstad.Unit();

    this.update = function() {
        // <movement depending on user action>
    };
};
